package lc

import "fmt"

func convert(s string, numRows int) string {
	var res []byte
	if numRows >= len(s) || numRows == 1 {
		return s
	}
	down := true
	//构造
	t := make([][]byte, 0)
	for i := 0; i < numRows; i++ {
		t = append(t, make([]byte, 0))
	}

	//插入
	row := 0
	for i := 0; i < len(s); i++ {
		t[row] = append(t[row], s[i])
		//判断 /翻转方向
		if i != 0 {
			if row+1 == numRows || row-1 < 0 {
				down = !down
			}
		}
		if down {
			row++
		} else {
			row--
		}
	}

	for i := 0; i < numRows; i++ {
		for j := 0; j < len(t[i]); j++ {
			res = append(res, t[i][j])
		}
	}
	return string(res)
}

func T6() {
	a := convert("LEETCODEISHIRING", 4)
	fmt.Println(a)
}

func foo() {

}
